from flask import Flask
from flask_cors import CORS


def create_app(config_object: str = "config.Config") -> Flask:
    """
    Flask application factory.

    :param config_object: Python path of the configuration object.
    :return: Configured Flask application.
    """
    app = Flask(__name__)
    app.config.from_object(config_object)

    CORS(
        app,
        resources={r"/api/*": {"origins": "*"}},
        supports_credentials=False,
        max_age=86400,
    )

    from .routes import api_bp

    app.register_blueprint(api_bp, url_prefix="/api")

    @app.route("/health", methods=["GET"])
    def health_check():
        return {"status": "ok"}, 200

    return app

